package edu.jmu.bean.message;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import edu.jmu.bean.user.User;

/***
 * 
 * @author Geven7
 *
 */
@Entity
public class MessageToUser  implements java.io.Serializable {
	private static final long serialVersionUID = -1079725653090756855L;
	private Integer id;
     private Message message;
     private User toUser;
     private User fromUser;
	private Integer isRead = 0;  //0未读,1已读
     
    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    public Integer getId() {
        return this.id;
    }
    
    public void setId(Integer id) {
        this.id = id;
    }
	@ManyToOne(cascade=CascadeType.REFRESH,fetch=FetchType.EAGER)
	@JoinColumn(name="message_Id", nullable=false)
    public Message getMessage() {
        return this.message;
    }
    
    public void setMessage(Message message) {
        this.message = message;
    }

	@ManyToOne(cascade=CascadeType.REFRESH,fetch=FetchType.LAZY)
    	@JoinColumn(name="fromUserName")
	public User getFromUser() {
		return fromUser;
	}
	
	public void setFromUser(User fromUser) {
		this.fromUser = fromUser;
	}

	@ManyToOne(fetch=FetchType.LAZY)
    	@JoinColumn(name="toUserName")
	public User getToUser() {
		return toUser;
	}

	public void setToUser(User toUser) {
		this.toUser = toUser;
	}
    
    @Column(nullable=false)
    public Integer getIsRead() {
        return this.isRead;
    }
    public void setIsRead(Integer isRead) {
        this.isRead = isRead;
    }
    
    @Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MessageToUser other = (MessageToUser) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
}